home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / pc / Code / Chapter09 / ChangeSegments2Panel.java < prev    next >
Text File  |  2000-11-15  |  2KB  |  77 lines

  1.  
  2. package applets;
  3.  
  4. import shout3d.*;
  5. import shout3d.core.*;
  6. import shout3d.math.*;
  7.  
  8.  
  9. public class ChangeSegments2Panel extends Shout3DPanel implements DeviceObserver {
  10.    
  11.    
  12.    TimeSensor timer;
  13.    FractionRemapper fr;
  14.    float[] first = {0.0f, .19f};
  15.    float[] second = {.2f, 1.0f};
  16.    boolean firstseg = false;
  17.   
  18.  
  19.    public ChangeSegments2Panel (Shout3DApplet applet){
  20.       super(applet);
  21.    }
  22.       
  23.    public void customInitialize() {
  24.       addDeviceObserver(this,"MouseInput", null);
  25.  
  26.  
  27.       timer = (TimeSensor) getNodeByName("timer");
  28.       fr = (FractionRemapper) getNodeByName("fr");
  29.       
  30.    }
  31.  
  32.  
  33.    protected void finalize()  { 
  34.       removeDeviceObserver(this,"MouseInput");
  35.  
  36.    }
  37.  
  38.    
  39.    
  40.    public boolean onDeviceInput(DeviceInput di, Object userData) {
  41.       MouseInput mi = (MouseInput) di;
  42.       switch (mi.which){
  43.  
  44.          case MouseInput.DOWN:
  45.          
  46.             if(firstseg) {
  47.             
  48.                timer.loop.setValue(false);
  49.                timer.stop();      
  50.                timer.cycleInterval.setValue(8.0);
  51.                fr.startKey.setValue(second[0]);
  52.                fr.endKey.setValue(second[1]);
  53.                timer.start();
  54.                timer.loop.setValue(true);               
  55.                firstseg = false;   
  56.                return true;
  57.             }
  58.             else {
  59.                timer.loop.setValue(false);
  60.                timer.stop();
  61.                timer.cycleInterval.setValue(2.0);
  62.                fr.startKey.setValue(first[0]);
  63.                fr.endKey.setValue(first[1]);
  64.                timer.start();
  65.                timer.loop.setValue(true);   
  66.  
  67.                firstseg = true;   
  68.                return true;
  69.             }
  70.                         
  71.       }//end of switch
  72.       
  73.       return false;
  74.    }
  75.  
  76.  
  77. }//end of class